<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>越南时事新闻汉越双语平行语料库 - 主页</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Microsoft YaHei', 'PingFang SC', 'Helvetica Neue', Arial, sans-serif;
            background: #f5f5f5;
            min-height: 100vh;
        }

        /* 顶部导航栏 */
        .header {
            background: #c41e3a;
            color: white;
            padding: 0 20px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .logo {
            display: flex;
            align-items: center;
            font-size: 18px;
            font-weight: bold;
        }

        .logo::before {
            content: "🏛️";
            margin-right: 8px;
            font-size: 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }

        .user-avatar {
            width: 32px;
            height: 32px;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 16px;
        }

        .logout-btn {
            background: rgba(255, 255, 255, 0.2);
            color: white;
            border: none;
            padding: 6px 12px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 14px;
            transition: background 0.3s ease;
        }

        .logout-btn:hover {
            background: rgba(255, 255, 255, 0.3);
        }

        /* 主内容区域 */
        .main-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 40px 20px;
        }

        /* 欢迎区域 */
        .welcome-section {
            background: #c41e3a;
            color: white;
            padding: 40px;
            border-radius: 12px;
            margin-bottom: 40px;
            text-align: center;
            box-shadow: 0 8px 32px rgba(196, 30, 58, 0.2);
        }

        .welcome-title {
            font-size: 28px;
            font-weight: bold;
            margin-bottom: 10px;
        }

        .welcome-subtitle {
            font-size: 16px;
            opacity: 0.9;
        }

        /* 功能卡片区域 */
        .features-section {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 40px;
            margin-bottom: 40px;
            max-width: 1000px;
            margin-left: auto;
            margin-right: auto;
        }

        .feature-card {
            background: white;
            border-radius: 16px;
            padding: 50px 40px;
            box-shadow: 0 8px 32px rgba(0,0,0,0.12);
            transition: all 0.3s ease;
            cursor: pointer;
            position: relative;
            overflow: hidden;
            min-height: 280px;
        }

        .feature-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #c41e3a 0%, #ffd700 100%);
        }

        .feature-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 32px rgba(0,0,0,0.15);
        }

        .feature-icon {
            width: 80px;
            height: 80px;
            margin: 0 auto 30px;
            position: relative;
        }

        /* 语料库管理图标 - 文件夹 */
        .icon-library {
            position: relative;
        }

        .icon-library::before {
            content: '';
            position: absolute;
            left: 10px;
            top: 20px;
            width: 60px;
            height: 40px;
            background: #c41e3a;
            border-radius: 4px;
            box-shadow: 0 4px 12px rgba(196, 30, 58, 0.3);
        }

        .icon-library::after {
            content: '';
            position: absolute;
            left: 10px;
            top: 15px;
            width: 30px;
            height: 8px;
            background: #c41e3a;
            border-radius: 4px 4px 0 0;
        }

        .icon-library .folder-front {
            position: absolute;
            left: 15px;
            top: 25px;
            width: 50px;
            height: 30px;
            background: linear-gradient(135deg, #e74c3c, #c41e3a);
            border-radius: 2px;
            box-shadow: inset 0 2px 4px rgba(255,255,255,0.2);
        }

        /* 创建语料库图标 - 加号 */
        .icon-create {
            position: relative;
            background: linear-gradient(135deg, #ffd700, #f39c12);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            box-shadow: 0 4px 12px rgba(255, 215, 0, 0.4);
        }

        .icon-create::before {
            content: '';
            position: absolute;
            width: 4px;
            height: 40px;
            background: white;
            border-radius: 2px;
        }

        .icon-create::after {
            content: '';
            position: absolute;
            width: 40px;
            height: 4px;
            background: white;
            border-radius: 2px;
        }



        .feature-title {
            font-size: 24px;
            font-weight: bold;
            color: #c41e3a;
            margin-bottom: 15px;
            text-align: center;
        }

        .feature-description {
            color: #666;
            line-height: 1.6;
            text-align: center;
            font-size: 16px;
        }


        /* 响应式设计 */
        @media (max-width: 768px) {
            .main-container {
                padding: 20px;
            }

            .features-section {
                grid-template-columns: 1fr;
                gap: 30px;
                max-width: 500px;
            }

            .feature-card {
                padding: 40px 30px;
                min-height: 250px;
            }

            .feature-icon {
                width: 70px;
                height: 70px;
                margin-bottom: 25px;
            }

            .feature-title {
                font-size: 22px;
            }

            .feature-description {
                font-size: 15px;
            }
        }

        /* 加载动画 */
        .loading {
            display: none;
            text-align: center;
            padding: 20px;
        }

        .loading-spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 2px solid #f3f3f3;
            border-top: 2px solid #c41e3a;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <!-- 顶部导航栏 -->
    <header class="header">
        <div class="logo">
            <span>越南时事新闻汉越双语平行语料库</span>
        </div>
        <div class="user-info">
            <div class="user-avatar">👤</div>
            <span id="userName">用户</span>
            <button class="logout-btn" onclick="logout()">退出登录</button>
        </div>
    </header>

    <!-- 主内容区域 -->
    <main class="main-container">

        <!-- 功能卡片区域 -->
        <section class="features-section">
            <div class="feature-card" onclick="navigateTo('corpus-libraries')">
                <div class="feature-icon icon-library">
                    <div class="folder-front"></div>
                </div>
                <h3 class="feature-title">语料库管理</h3>
                <p class="feature-description">创建、编辑和管理汉越双语语料库，支持分类和搜索功能</p>
            </div>

            <div class="feature-card" onclick="navigateTo('create-library')">
                <div class="feature-icon icon-create">
                </div>
                <h3 class="feature-title">创建语料库</h3>
                <p class="feature-description">快速创建新的汉越双语平行语料库</p>
            </div>
        </section>


        <!-- 加载动画 -->
        <div class="loading" id="loading">
            <div class="loading-spinner"></div>
            <span style="margin-left: 10px;">加载中...</span>
        </div>
    </main>

    <script>
        // 页面加载时检查登录状态
        window.addEventListener('load', function() {
            checkLoginStatus();
        });

        // 检查登录状态
        function checkLoginStatus() {
            const token = localStorage.getItem('token');
            const user = localStorage.getItem('user');
            
            if (!token) {
                // 未登录，跳转到登录页
                window.location.href = 'login.html';
                return;
            }
            
            // 显示用户信息
            if (user) {
                try {
                    const userData = JSON.parse(user);
                    document.getElementById('userName').textContent = userData.username || '用户';
                } catch (e) {
                    console.error('解析用户信息失败:', e);
                }
            }
        }


        // 导航到不同页面
        function navigateTo(page) {
            switch(page) {
                case 'corpus-libraries':
                    window.location.href = 'corpus-libraries.html';
                    break;
                case 'create-library':
                    window.location.href = 'corpus-library-create.html';
                    break;
                default:
                    console.log('导航到:', page);
            }
        }

        // 退出登录
        async function logout() {
            if (confirm('确定要退出登录吗？')) {
                try {
                    // 调用后端登出接口
                    await fetch('/auth/logout', {
                        method: 'POST',
                        headers: {
                            'Authorization': `Bearer ${localStorage.getItem('token')}`,
                            'Content-Type': 'application/json'
                        }
                    });
                } catch (error) {
                    console.error('登出请求失败:', error);
                } finally {
                    // 清除本地存储
                    localStorage.removeItem('token');
                    localStorage.removeItem('user');
                    
                    // 跳转到登录页
                    window.location.href = 'login.html';
                }
            }
        }

        // 定期检查token有效性
        setInterval(() => {
            const token = localStorage.getItem('token');
            if (!token) {
                window.location.href = 'login.html';
            }
        }, 30000); // 每30秒检查一次
    </script>
</body>
</html>
